package edu.hz.controller;

import com.alibaba.fastjson.JSON;
import edu.hz.model.dto.UserInfoDto;
import edu.hz.model.dto.UserLoginDto;
import edu.hz.model.dto.UserRegisterDto;
import edu.hz.service.UserService;
import edu.hz.util.web.ApiResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
public class UserController {

    @Resource
    UserService userService;

    @GetMapping("/all-users")
    public ApiResponse<List<UserInfoDto>> allUsers() {
        return ApiResponse.success(userService.allUsers());
    }

    @PostMapping("/user/register")
    public ApiResponse<Void> registerUser(@RequestBody UserRegisterDto userRegisterDto) {
        return userService.addUser(userRegisterDto);
    }

    @PostMapping("/user/login")
    public ApiResponse<String> login(@RequestBody UserLoginDto userLoginDto) {
        return userService.login(userLoginDto);
    }



}
